package com.lxb.eduservice.controller;


import com.lxb.commonutils.R;
import com.lxb.eduservice.entity.subject.OneSubject;
import com.lxb.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 课程分类管理 前端控制器
 *
 * @author lixuebin
 * @since 2022-10-29
 */

@Api(description = "课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
//@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    /**
     * 添加课程分类
     *
     * @param file 获取上传的文件
     * @return
     */
    @ApiOperation(value = "添加课程分类")
    @PostMapping("/upSubject")
    public R upSubject(@ApiParam(name = "file" ,value = "上传文件",required = true) MultipartFile file) {

        subjectService.saveSubject(file, subjectService);
        return R.ok();
    }

    @ApiOperation(value = "查询所有课程分类列表(树形展示)")
    @GetMapping("/getAllSubject")
    public R getAllSubject(){
        List<OneSubject> list = subjectService.getAllOneTwoSubject();
        return R.ok().data("list",list);
    }

}

